//
//  HomeTableViewCell.m
//  afn
//
//  Created by mac on 2018/5/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "ShopViewController.h"
@implementation HomeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(CGFloat)creatView{
    UIView *beiJingView=[UIView new];
    [self addSubview:beiJingView];
    [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
    }];
    beiJingView.backgroundColor=[UIColor whiteColor];
    
    
    UIImageView *imageView=[UIImageView new];
    [beiJingView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(10);
        make.width.height.mas_equalTo(70);
    }];
    NSString *shop_image=_model.shop_image;
    [imageView sd_setImageWithURL:[NSURL URLWithString:shop_image]];

    UILabel *nameLabel=[UILabel new];
    [beiJingView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_right).mas_equalTo(5);
        make.right.mas_equalTo(-60);
        make.top.mas_equalTo(imageView);
    }];
    nameLabel.text=_model.shop_name;
    nameLabel.textColor=ColorWithRGB(29, 29, 29);
    nameLabel.font=[UIFont systemFontOfSize:14];
    
    UILabel *juLiLabel=[UILabel new];
    [beiJingView addSubview:juLiLabel];
    [juLiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(imageView);
    }];
    juLiLabel.textColor=ColorWithRGB(149, 149, 149);
    juLiLabel.font=[UIFont systemFontOfSize:12];
    juLiLabel.text=_model.distance;
    
    if (_model.shop_service_score.doubleValue==0||_model.shop_service_score==nil) {
        UILabel *pingFenLabel=[UILabel new];
        [beiJingView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel);
            make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(5);
        }];
        pingFenLabel.text=@"暂无评分";
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        pingFenLabel.font=[UIFont systemFontOfSize:12];
    }
    else{
        for (int i=0; i<_model.shop_service_score.integerValue; i++) {
            UIImageView *fenImge=[UIImageView new];
            [beiJingView addSubview:fenImge];
            [fenImge mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(nameLabel.mas_left).mas_equalTo(20*i);
                make.height.mas_equalTo(12);
                make.width.mas_equalTo(15);
                make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(5);
            }];
            fenImge.image=[UIImage imageNamed:@"ico-zuanshi"];
        }
        
        UILabel *pingFenLabel=[UILabel new];
        [beiJingView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel.mas_left).mas_equalTo(20*self->_model.shop_service_score.intValue);
            make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(7);
        }];
        pingFenLabel.text=[NSString stringWithFormat:@"%2.f",_model.shop_service_score.doubleValue];
        pingFenLabel.font=[UIFont systemFontOfSize:12];
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        
    }
    
    UILabel *hangYelabel=[UILabel new];
    [beiJingView addSubview:hangYelabel];
    [hangYelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.bottom.mas_equalTo(imageView);
    }];
    hangYelabel.textColor=ColorWithRGB(29, 29, 29);
    hangYelabel.text=_model.shopcategory;
    hangYelabel.font=[UIFont systemFontOfSize:12];
    
    UILabel *addLabel=[UILabel new];
    [beiJingView addSubview:addLabel];
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(imageView);
        make.right.mas_equalTo(-10);
    }];
    addLabel.textColor=ColorWithRGB(149, 149, 149);
    addLabel.font=[UIFont systemFontOfSize:12];
    addLabel.text=_model.address;
    return 100;
}

-(CGFloat)creatView2{
    
    UIView *beiJingView=[UIView new];
    [self addSubview:beiJingView];
    [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
    }];
    beiJingView.backgroundColor=[UIColor whiteColor];
    
    UIView *dianJiView=[UIView new];
    
    
    UIImageView *imageView=[UIImageView new];
    [beiJingView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(10);
        make.width.height.mas_equalTo(70);
    }];
    NSString *shop_image=_model.shop_image;
    [imageView sd_setImageWithURL:[NSURL URLWithString:shop_image]];
    
    UILabel *nameLabel=[UILabel new];
    [beiJingView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_right).mas_equalTo(5);
        make.right.mas_equalTo(-60);
        make.top.mas_equalTo(imageView);
    }];
    nameLabel.text=_model.shop_name;
    nameLabel.textColor=ColorWithRGB(29, 29, 29);
    nameLabel.font=[UIFont systemFontOfSize:14];
    
    UILabel *juLiLabel=[UILabel new];
    [beiJingView addSubview:juLiLabel];
    [juLiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(imageView);
    }];
    juLiLabel.textColor=ColorWithRGB(149, 149, 149);
    juLiLabel.font=[UIFont systemFontOfSize:12];
    juLiLabel.text=_model.distance;
    
    if (_model.shop_service_score.doubleValue==0||_model.shop_service_score==nil) {
        UILabel *pingFenLabel=[UILabel new];
        [beiJingView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel);
            make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(5);
        }];
        pingFenLabel.text=@"暂无评分";
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        pingFenLabel.font=[UIFont systemFontOfSize:12];
    }
    else{
        for (int i=0; i<_model.shop_service_score.integerValue; i++) {
            UIImageView *fenImge=[UIImageView new];
            [beiJingView addSubview:fenImge];
            [fenImge mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(nameLabel.mas_left).mas_equalTo(20*i);
                make.height.mas_equalTo(12);
                make.width.mas_equalTo(15);
                make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(5);
            }];
            fenImge.image=[UIImage imageNamed:@"ico-zuanshi"];
        }
        
        UILabel *pingFenLabel=[UILabel new];
        [beiJingView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel.mas_left).mas_equalTo(20*self->_model.shop_service_score.intValue);
            make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(3);
        }];
        pingFenLabel.text=[NSString stringWithFormat:@"%2.f分",_model.shop_service_score.floatValue];
        pingFenLabel.font=[UIFont systemFontOfSize:12];
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        
    }
    
    UILabel *hangYelabel=[UILabel new];
    [beiJingView addSubview:hangYelabel];
    [hangYelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.bottom.mas_equalTo(imageView);
    }];
    hangYelabel.textColor=ColorWithRGB(29, 29, 29);
    hangYelabel.text=@"没发";
    hangYelabel.font=[UIFont systemFontOfSize:12];
    
    UIImageView *tuiJian=[UIImageView new];
    [beiJingView addSubview:tuiJian];
    [tuiJian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(hangYelabel.mas_right).mas_equalTo(5);
        make.centerY.mas_equalTo(hangYelabel);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(10);
    }];
    tuiJian.image=[UIImage imageNamed:@"ico-tuijian"];
    
    UILabel *addLabel=[UILabel new];
    [beiJingView addSubview:addLabel];
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(imageView);
        make.right.mas_equalTo(-10);
        make.left.mas_equalTo(tuiJian.mas_right).mas_equalTo(5);
    }];
    addLabel.textColor=ColorWithRGB(149, 149, 149);
    addLabel.font=[UIFont systemFontOfSize:12];
    addLabel.text=_model.address;
    addLabel.textAlignment=NSTextAlignmentRight;


    if (_model.hairdresser!=nil&&_model.hairdresser.count!=0) {
        UIView *XianView=[UIView new];
        [beiJingView addSubview:XianView];
        [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
            make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(15);
            make.height.mas_equalTo(1);
        }];
        XianView.backgroundColor=_LightGrey;
        
        if (_model.hairdresser.count>=2) {
            for (int i=0; i<2; i++) {
                UIView *shopView=[UIView new];
                [beiJingView addSubview:shopView];
                [shopView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.right.mas_equalTo(0);
                    make.top.mas_equalTo(XianView.mas_bottom).mas_equalTo(61*i);
                    make.height.mas_equalTo(60);
                }];
                
                
                UILabel *priceLabel=[UILabel new];
                [shopView addSubview:priceLabel];
                [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.centerY.mas_equalTo(0);
                }];
                priceLabel.textColor=_backgroundColor;
                priceLabel.text=@"¥ 78";
                priceLabel.font=[UIFont systemFontOfSize:20];
                
                UILabel *faShiLabel=[UILabel new];
                [shopView addSubview:faShiLabel];
                [faShiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(nameLabel);
                    make.right.mas_equalTo(-90);
                    make.bottom.mas_equalTo(priceLabel.mas_centerY).mas_equalTo(-2);
                }];
                faShiLabel.text=@"爱思特首希设计师精剪发";
                faShiLabel.font=[UIFont systemFontOfSize:12];
                faShiLabel.textColor=ColorWithRGB(29, 29, 29);
                
                UILabel *VIPLabel=[UILabel new];
                [shopView addSubview:VIPLabel];
                [VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(nameLabel);
                    make.top.mas_equalTo(priceLabel.mas_centerY).mas_equalTo(2);
                    make.width.mas_equalTo(25);
                    make.height.mas_equalTo(15);
                }];
                VIPLabel.text=@"VIP";
                VIPLabel.font=[UIFont systemFontOfSize:12];
                VIPLabel.textColor=[UIColor whiteColor];
                VIPLabel.backgroundColor=_backgroundColor;
                VIPLabel.textAlignment=NSTextAlignmentCenter;
                CGSize size=[gongju getNSStringWeight:@"¥78" andViewWight:20 andFont:13];
                UILabel *priceLabel2=[UILabel new];
                [shopView addSubview:priceLabel2];
                [priceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(VIPLabel.mas_right);
                    make.height.top.mas_equalTo(VIPLabel);
                    make.width.mas_equalTo(size.width+8);
                }];
                priceLabel2.textColor=_backgroundColor;
                priceLabel2.font=[UIFont systemFontOfSize:12];
                priceLabel2.text=@"¥78";
                priceLabel2.layer.borderColor=_backgroundColor.CGColor;
                priceLabel2.layer.borderWidth=1;
                priceLabel2.textAlignment=NSTextAlignmentCenter;
                
                UILabel *xiaoLiangLabel=[UILabel new];
                [shopView addSubview:xiaoLiangLabel];
                [xiaoLiangLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(-10);
                    make.centerY.mas_equalTo(0);
                }];
                xiaoLiangLabel.text=@"已售180";
                xiaoLiangLabel.textColor=ColorWithRGB(149, 149, 149);
                xiaoLiangLabel.font=[UIFont systemFontOfSize:12];
                
                if (i==0) {
                    UIView *XianView2=[UIView new];
                    [beiJingView addSubview:XianView2];
                    [XianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.left.mas_equalTo(10);
                        make.right.mas_equalTo(-10);
                        make.top.mas_equalTo(shopView.mas_bottom).mas_equalTo(0);
                        make.height.mas_equalTo(1);
                    }];
                    XianView2.backgroundColor=_LightGrey;
                }
                
            }
    
            UIView *XianView3=[UIView new];
            [beiJingView addSubview:XianView3];
            [XianView3 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.height.right.mas_equalTo(XianView);
                make.top.mas_equalTo(XianView.mas_bottom).mas_equalTo(121);
            }];
            XianView3.backgroundColor=_LightGrey;
            
            UIView *MoreView=[UIView new];
            [beiJingView addSubview:MoreView];
            [MoreView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.bottom.mas_equalTo(0);
                make.height.mas_equalTo(30);
            }];
            
            UILabel *moreLabel=[UILabel new];
            [MoreView addSubview:moreLabel];
            [moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(0);
            }];
            moreLabel.textColor=ColorWithRGB(149, 149, 149);
            moreLabel.text=@"其他4个服务";
            moreLabel.font=[UIFont systemFontOfSize:14];
            
            UIImageView *moreImage=[UIImageView new];
            [MoreView addSubview:moreImage];
            [moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(moreLabel.mas_right).mas_equalTo(3);
                make.centerY.mas_equalTo(0);
                make.width.mas_equalTo(20);
                make.height.mas_equalTo(10);
            }];
            moreImage.image=[UIImage imageNamed:@"ico-xiala"];
        
    
        }


    }else{
        return 100;
    }

    return 272;
}

#pragma mark————————————————————点击屏幕关闭键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self ];
    if (touchPoint.y<=100) {
         if (_model.shop_id) {
            ShopViewController *shopView=[[ShopViewController alloc] init];
            shopView.shop_id=_model.shop_id;
            [gongju pushNextViewController:self.viewController andRootController:shopView];
         }
        
    }
    
    
}

@end
